﻿using System.Threading;
using com.fukefu.tools;

namespace com.fukefu.url
{
    public partial class UrlShouluForm : BaseForm
    {
        private static UrlShouluForm ks = null;
        private static object syncObject = new object();
        //单例模式
        public static UrlShouluForm GetInstance()
        {
            if (ks == null || ks.IsDisposed)
            {
                lock (syncObject)
                {
                    if (ks == null || ks.IsDisposed)
                    {
                        ks = new UrlShouluForm();
                    }
                }
            }
            return ks;
        }
        UrlSholu urlShoulu = new UrlSholu();
        SiteCollection sc = new SiteCollection();
        //构造函数
        private UrlShouluForm()
        {
            InitializeComponent();
            //委托传递
            urlShoulu.SetControl += SetControl;
            urlShoulu.GetControl += GetControl;
            //加载网址列表
            sc.LoadToComboBox(comboBox1);
            //设置时间dtpk1的默认值
            this.dtpk1.Value = this.dtpk1.Value.AddDays(-2);
            //文本框特色处理
            this.listBox1.DrawItem += new System.Windows.Forms.DrawItemEventHandler(this.listBox_DrawItem);
        }
        //开始按钮
        private void BeginButton_Click(object sender, System.EventArgs e)
        {
            this.listBox1.Items.Clear();
            new Thread(new ParameterizedThreadStart(urlShoulu.CheckWebPagesShouLu)).Start(GetCanshu());
            this.button1.Enabled = false;
        }
        //获取组合参数
        private string GetCanshu()
        {
            string url = sc.GetDomain(comboBox1);
            string date1 = dtpk1.Value.Date.ToShortDateString();
            string date2 = dtpk2.Value.Date.AddDays(1).ToShortDateString();
            return (url == null ? "" : "domain='" + url + "' and") + " dt between '" + date1 + "' and '" + date2 + "' ";
        }
    }
}
